# -*- conding: utf-8 -*-


import sys, pygame
from random import randrange
from pygame.locals import KEYDOWN, QUIT
from itertools import count

size = width, height = 480, 480
right = (10, 0)
pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode(size)

snake_dir = right
snake = [pygame.Rect(10, 10 + value * 10, 10, 10) for value in range(20)]
foreground, background = (255, 255, 255), (0, 0, 0)

for counter in count():
    clock.tick(min(5 + (len(snake) / 4), 30))
    event = pygame.event.poll()

    if event.type == QUIT:
        pygame.quit()
        sys.exit()

    next = snake[-1].move(snake_dir)
    snake.append(next)
    del snake[0]
    screen.fill(background)
    
    for rect in snake:
        pygame.draw.rect(screen, foreground, rect)
    pygame.display.flip()
